package com.zhiyou.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhiyou.model.System_A;
import com.zhiyou.service.SystemService;
import com.zhiyou.utils.JsonResult;

@RestController
@RequestMapping("system/")
public class SystemController {

	@Autowired
	SystemService service;

	// 查询系统消息
	@GetMapping(value = "list")
	public JsonResult show(HttpServletRequest request, HttpServletResponse response) {

		return new JsonResult(service.select(), "查询成功");
	}

	// 添加系统消息
	@PostMapping("add")
	public JsonResult add(System_A system_A, HttpServletRequest request, HttpServletResponse response) {
		service.add(system_A);
		System.out.println(system_A);
		return new JsonResult("添加成功");
	}

	// 删除系统消息
	@DeleteMapping("delete/{system_id}")
	public JsonResult delete(@PathVariable("system_id")Integer id, HttpServletRequest request, HttpServletResponse response) {
		service.delete(id);
		return new JsonResult("删除成功");

	}

	// 修改系统消息
	@PutMapping("update")
	public JsonResult update(System_A system_A, HttpServletRequest request, HttpServletResponse response) {
		service.update(system_A);
		return new JsonResult("修改成功");

	}
}
